import mysql.connector
import os
import json

# 连接数据库
conn = mysql.connector.connect(
    host=os.environ.get('MYSQL_HOST', '106.54.18.228'),
    user=os.environ.get('MYSQL_USER', 'admin'),
    password=os.environ.get('MYSQL_PASSWORD', '831114399x'),
    database=os.environ.get('MYSQL_DATABASE', 'person_db'),
    port=int(os.environ.get('MYSQL_PORT', 33306))
)

cursor = conn.cursor()
cursor.execute('SELECT schedule_data FROM schedules WHERE room_number = %s;', ('104',))
result = cursor.fetchone()
conn.close()

# 解析排班数据并统计总数
schedule = json.loads(result[0])
total_shifts = 0
for day in schedule:
    shifts = day['shifts']
    for shift_name, shift_persons in shifts.items():
        total_shifts += len(shift_persons)
        
print(total_shifts)